using UnityEngine;

public class PlayerAnimation : MonoBehaviour
{
    private Animator ani;
    private int crouchID;
    private int fallID;

    //Ӧ�ò�����������Ϊ���ֿͻ��˶����ַ������͵Ĵ����ϻ�������⣬
    //unity�����ｨ����int���������
    private int groundID;
    private int hangingID;
    private PlayerMove playerMove;
    private Rigidbody2D rb;

    private int speedID;

    // Start is called before the first frame update
    private void Start()
    {
        ani = GetComponent<Animator>();
        playerMove = GetComponentInParent<PlayerMove>();
        rb = GetComponentInParent<Rigidbody2D>();

        groundID = Animator.StringToHash("isOnGround");
        hangingID = Animator.StringToHash("isHanging");
        crouchID = Animator.StringToHash("isCrouching");
        speedID = Animator.StringToHash("Speed");
        fallID = Animator.StringToHash("verticalVelocity");
    }

    // Update is called once per frame
    private void Update()
    {
        //ani.SetFloat(speedID, Mathf.Abs(playerMove.xVelocity));
        ani.SetBool(groundID, playerMove.isOnGround);
        ani.SetBool(hangingID, playerMove.isHanding);
        ani.SetBool(crouchID, playerMove.isCrouch);
        ani.SetFloat(fallID, rb.velocity.y);
    }
}